<template>
  <div class="ma-content-block lg:flex justify-between p-4">
    <!-- CRUD 组件 -->
    <ma-crud :options="options" :columns="columns" ref="crudRef">
      <template #tableBeforeButtons>
        <a-link  href="/#/goods/info/create" >新增商品</a-link>
      </template>
    </ma-crud>
  </div>
</template>
<script setup>
import { ref, reactive } from 'vue'
import goodsInfo from '@/api/goods/goodsInfo'
import { Message } from '@arco-design/web-vue'
import tool from '@/utils/tool'
import * as common from '@/utils/common'

const crudRef = ref()


const numberOperation = (newValue, id, numberName) => {
  goodsInfo.numberOperation({ id, numberName, numberValue: newValue }).then( res => {
    res.success && Message.success(res.message)
  }).catch( e => { console.log(e) } )
}

const switchStatus = (statusValue, id, statusName) => {
  goodsInfo.changeStatus({ id, statusName, statusValue }).then( res => {
    res.success && Message.success(res.message)
  }).catch( e => { console.log(e) } )
}


const options = reactive({
  id: 'goods_info',
  rowSelection: {
    showCheckedAll: true
  },
  pk: 'goods_id',
  operationColumn: true,
  operationColumnWidth: 160,
  formOption: {
    viewType: 'modal',
    width: 600
  },
  api: goodsInfo.getList,
  recycleApi: goodsInfo.getRecycleList,
  edit: {
    show: true,
    api: goodsInfo.update,
    auth: ['goods:info:update']
  }

})

const columns = reactive([
  {
    title: "商品ID",
    dataIndex: "goods_id",
    formType: "input",
    addDisplay: false,
    editDisplay: false,
    commonRules: {
      required: true,
      message: "请输入商品ID"
    }
  },
  {
    title: "商品类型(10实物商品)",
    dataIndex: "goods_type",
    formType: "input",
    search: true,
    commonRules: {
      required: true,
      message: "请输入商品类型(10实物商品)"
    }
  },
  {
    title: "商品名称",
    dataIndex: "goods_name",
    formType: "input",
    search: true,
    commonRules: {
      required: true,
      message: "请输入商品名称"
    }
  },
  {
    title: "商品编码",
    dataIndex: "goods_no",
    formType: "input",
    addDisplay: false,
    editDisplay: false,
    commonRules: {
      required: true,
      message: "请输入商品编码"
    }
  },
  {
    title: "主图视频ID",
    dataIndex: "video_id",
    formType: "input",
    commonRules: {
      required: true,
      message: "请输入主图视频ID"
    }
  },
  {
    title: "主图视频ID",
    dataIndex: "video_cover_id",
    formType: "input",
    commonRules: {
      required: true,
      message: "请输入主图视频ID"
    }
  },
  {
    title: "商品卖点",
    dataIndex: "selling_point",
    formType: "input",
    commonRules: {
      required: true,
      message: "请输入商品卖点"
    }
  },
  {
    title: "商品规格(10单规格 20多规格)",
    dataIndex: "spec_type",
    formType: "input",
    commonRules: {
      required: true,
      message: "请输入商品规格(10单规格 20多规格)"
    }
  },
  {
    title: "商品价格(最低)",
    dataIndex: "goods_price_min",
    formType: "input",
    commonRules: {
      required: true,
      message: "请输入商品价格(最低)"
    }
  },
  {
    title: "商品价格(最高)",
    dataIndex: "goods_price_max",
    formType: "input",
    commonRules: {
      required: true,
      message: "请输入商品价格(最高)"
    }
  },
  {
    title: "划线价格(最低)",
    dataIndex: "line_price_min",
    formType: "input"
  },
  {
    title: "划线价格(最高)",
    dataIndex: "line_price_max",
    formType: "input"
  },
  {
    title: "库存总量(包含所有sku)",
    dataIndex: "stock_total",
    formType: "input",
    commonRules: {
      required: true,
      message: "请输入库存总量(包含所有sku)"
    }
  },
  {
    title: "库存计算方式(10下单减库存 20付款减库存)",
    dataIndex: "deduct_stock_type",
    formType: "input",
    commonRules: {
      required: true,
      message: "请输入库存计算方式(10下单减库存 20付款减库存)"
    }
  },
  {
    title: "是否开启限购(0未开启 1已开启)",
    dataIndex: "is_restrict",
    formType: "input",
    commonRules: {
      required: true,
      message: "请输入是否开启限购(0未开启 1已开启)"
    }
  },
  {
    title: "总限购数量(0为不限制)",
    dataIndex: "restrict_total",
    formType: "input",
    commonRules: {
      required: true,
      message: "请输入总限购数量(0为不限制)"
    }
  },
  {
    title: "每单限购数量(0为不限制)",
    dataIndex: "restrict_single",
    formType: "input",
    commonRules: {
      required: true,
      message: "请输入每单限购数量(0为不限制)"
    }
  },
  {
    title: "商品详情",
    dataIndex: "content",
    formType: "editor",
    commonRules: {
      required: true,
      message: "请输入商品详情"
    }
  },
  {
    title: "初始销量",
    dataIndex: "sales_initial",
    formType: "input",
    commonRules: {
      required: true,
      message: "请输入初始销量"
    }
  },
  {
    title: "实际销量",
    dataIndex: "sales_actual",
    formType: "input",
    commonRules: {
      required: true,
      message: "请输入实际销量"
    }
  },
  {
    title: "配送模板ID",
    dataIndex: "delivery_id",
    formType: "input",
    commonRules: {
      required: true,
      message: "请输入配送模板ID"
    }
  },
  {
    title: "是否开启积分赠送(1开启 0关闭)",
    dataIndex: "is_points_gift",
    formType: "input",
    commonRules: {
      required: true,
      message: "请输入是否开启积分赠送(1开启 0关闭)"
    }
  },
  {
    title: "是否允许使用积分抵扣(1允许 0不允许)",
    dataIndex: "is_points_discount",
    formType: "input",
    commonRules: {
      required: true,
      message: "请输入是否允许使用积分抵扣(1允许 0不允许)"
    }
  },
  {
    title: "积分抵扣设置(0默认抵扣 1单独设置抵扣)",
    dataIndex: "is_alone_points_discount",
    formType: "input",
    commonRules: {
      required: true,
      message: "请输入积分抵扣设置(0默认抵扣 1单独设置抵扣)"
    }
  },
  {
    title: "单独设置积分抵扣的配置",
    dataIndex: "points_discount_config",
    formType: "input",
    commonRules: {
      required: true,
      message: "请输入单独设置积分抵扣的配置"
    }
  },
  {
    title: "是否开启会员折扣(1开启 0关闭)",
    dataIndex: "is_enable_grade",
    formType: "input",
    commonRules: {
      required: true,
      message: "请输入是否开启会员折扣(1开启 0关闭)"
    }
  },
  {
    title: "会员折扣设置(0默认等级折扣 1单独设置折扣)",
    dataIndex: "is_alone_grade",
    formType: "input",
    commonRules: {
      required: true,
      message: "请输入会员折扣设置(0默认等级折扣 1单独设置折扣)"
    }
  },
  {
    title: "单独设置折扣的配置",
    dataIndex: "alone_grade_equity",
    formType: "editor"
  },
  {
    title: "是否单独设置配送方式(0关闭 1开启)",
    dataIndex: "is_ind_delivery_type",
    formType: "input",
    commonRules: {
      required: true,
      message: "请输入是否单独设置配送方式(0关闭 1开启)"
    }
  },
  {
    title: "商品配送方式(仅单独设置时有效)",
    dataIndex: "delivery_type",
    formType: "input",
    commonRules: {
      required: true,
      message: "请输入商品配送方式(仅单独设置时有效)"
    }
  },
  {
    title: "商品状态(10上架 20下架)",
    dataIndex: "status",
    formType: "input",
    commonRules: {
      required: true,
      message: "请输入商品状态(10上架 20下架)"
    }
  },
  {
    title: "排序(数字越小越靠前)",
    dataIndex: "sort",
    formType: "input",
    commonRules: {
      required: true,
      message: "请输入排序(数字越小越靠前)"
    }
  },
  {
    title: "是否删除",
    dataIndex: "is_delete",
    formType: "input",
    commonRules: {
      required: true,
      message: "请输入是否删除"
    }
  },
  {
    title: "商城ID",
    dataIndex: "store_id",
    formType: "input",
    addDisplay: false,
    editDisplay: false,
    hide: true,
    commonRules: {
      required: true,
      message: "请输入商城ID"
    }
  },
  {
    title: "创建时间",
    dataIndex: "create_time",
    formType: "range",
    search: true,
    addDisplay: false,
    editDisplay: false,
    showTime: true
  },
  {
    title: "更新时间",
    dataIndex: "update_time",
    formType: "input",
    addDisplay: false,
    editDisplay: false,
    hide: true
  }
])
</script>
<script> export default { name: 'goods:info' } </script>